#include "stdafx.h"
#include "onlinePlayerMgr_t.h"


void onlinePlayerMgr_t::delPlayer( const UniqueID& player )
{
	threadSync_t ts(&m);
	opMap::iterator iter;
	iter = op.find(player);
	if (iter!=op.end())
	{
		op.erase(iter);
	}
}


void onlinePlayerMgr_t::switchPlayer( const UniqueID& player, int sceneid )
{
	threadSync_t ts(&m);
	opMap::iterator iter;
	iter = op.find(player);
	if (iter!=op.end())
	{
		iter->second = sceneid;
	}
	else
	{
		op.insert(make_pair(player,sceneid));
	}
}


int onlinePlayerMgr_t::getPlayerScene( const UniqueID& player )
{
	threadSync_t ts(&m);
	opMap::iterator iter;
	iter = op.find(player);
	if (iter!=op.end())
	{
		return iter->second;
	}
	return -1;
}


list<UniqueID> onlinePlayerMgr_t::getPlayers()
{
	threadSync_t ts(&m);
	list<UniqueID> uids;
	opMap::iterator iter;
	for (iter=op.begin(); iter!=op.end(); iter++)
	{
		uids.push_back(iter->first);
	}
	return uids;
}